package com.example.social.screen

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.NavHostController
import com.example.social.navigation.Routes
import com.example.social.utils.SharedPref

@Composable
fun Notification(navHostController: NavHostController,navController: NavHostController?) {
    Column(modifier = Modifier
        .fillMaxSize()
        .padding(16.dp)) {
        Text(
            text = "消息通知",
            fontSize = 24.sp,
            fontWeight = FontWeight.Bold,
            modifier = Modifier.padding(bottom = 16.dp)
        )
        LazyColumn(
            modifier = Modifier.fillMaxWidth()
        ) {
            items(listOf("回复我的", "正在关注")) { item ->
                if (navController != null) {
                    NotificationItem(
                        navController,
                        title = item,
                        iconRes = if (item == "查看话题评论") android.R.drawable.ic_menu_info_details else android.R.drawable.ic_menu_send
                    )
                }
            }
        }
    }
}

@Composable
fun NotificationItem( navHostController: NavHostController, title: String, iconRes: Int) {
    val context = LocalContext.current
    val currentId = SharedPref.getUid(context)
    Card(
        modifier = Modifier
            .fillMaxWidth()
            .padding(vertical = 8.dp)
            .clickable {
                if (title == "回复我的") {
                    val route = Routes.NotificationComment.routes.replace("{data}", currentId)
                    //进入详情页
                    navHostController.navigate(route)
                }else{
                    val route = Routes.FollowScreen.routes.replace("{data}", currentId)
                    navHostController.navigate(route)
                }
            },
        colors = CardDefaults.cardColors(containerColor = Color(0x4AB0CDF6))
    ) {
        Row(
            modifier = Modifier
                .padding(16.dp)
                .fillMaxWidth(),
            verticalAlignment = Alignment.CenterVertically
        ) {
            Icon(
                painter = painterResource(id = iconRes),
                contentDescription = title,
                tint = Color(0xFF8BA5F3),
                modifier = Modifier.size(20.dp)
            )
            Spacer(modifier = Modifier.width(10.dp))
            Text(
                text = title,
                fontSize = 18.sp,
                fontWeight = FontWeight.Medium,
                color = Color.Black
            )
        }
    }
}


